L1-023 输出GPLT

题目 L1-023 输出GPLT

image-c1a20754

思路分析

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

int main()

{

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	string s;cin>>s;

	map<char,int> hx;

	for(auto c:s){

		hx[toupper(c)]++;

	}

	int maxn=max({hx['G'],hx['P'],hx['L'],hx['T']});

//	cout<<maxn;

	while(maxn--){

		if(hx['G']!=0){

			cout<<"G";

			hx['G']--;

		}

		if(hx['P']!=0){

			cout<<"P";

			hx['P']--;

		}

		if(hx['L']!=0){

			cout<<"L";

			hx['L']--;

		}

		if(hx['T']!=0){

			cout<<"T";

			hx['T']--;

		}

	}

	return 0;

}

同类题型

视频讲解


⬅️ L1-022 奇偶分家 🏠 00-天梯赛 ➡️ L1-024 后天